<cfcomponent output="false">

	<!--- --->
	
	<cffunction name="saveDiscussion" access="public" output="true" returntype="boolean">

		<cfset var local = {} />
		
		<cfset $.run.it("discussionService.saveInitialDiscussion",arguments) />
		
		<cfset local.address = cgi.http_referer />
		
		<cfset local.address = $.link.setArg(local.address,"feedback") />
		
		<cflocation url="#local.address#" addToken="no" />
		
		<cfreturn true />
			
	</cffunction>
	
	<!--- --->
	
	<cffunction name="saveMessage" access="public" output="true" returntype="boolean">

		<cfset var local = {} />
		
		<cfset $.run.it("discussionService.saveMessage",arguments) />
		
		<cfset local.address = cgi.http_referer />
		
		<cfset local.address = $.link.setArg(local.address,"feedback") />
		<cfset local.address = $.link.setArg(local.address,"discussionID",arguments.discussionID) />
		
		<cflocation url="#local.address#" addToken="no" />
		
		<cfreturn true />
			
	</cffunction>
	
	<!--- --->
	
	<cffunction name="unFollowDiscussion" access="public" output="true" returntype="boolean">

		<cfset var local = {} />
		
		<cfset $.run.it("discussionService.unfollowDiscussion",arguments) />
		
		<cfset local.address = cgi.http_referer />
		
		<cfset local.address = $.link.setArg(local.address,"feedback") />
		<cfset local.address = $.link.removeArg(local.address,"discussionID") />
		
		<cflocation url="#local.address#" addToken="no" />
		
		<cfreturn true />
			
	</cffunction>
	
	<!--- --->
	
	<cffunction name="showCategory" access="public" output="true" returntype="boolean">
		<cfargument name="discussionCategoryID" required="true" />

		<cfset var local = {} />
		
		<cfset local.address = cgi.http_referer />
		
		<cfset local.address = $.link.setArg(local.address,"discussionCategoryID",arguments.discussionCategoryID) />
		
		<cflocation url="#local.address#" addToken="no" />
		
		<cfreturn true />
			
	</cffunction>
	
	<!--- --->
	
	<cffunction name="followDiscussion" access="public" output="true" returntype="boolean">
		<cfargument name="message" required="false" default="" />
		<cfargument name="subject" required="false" default="" />
		<cfargument name="discussionID" required="false" default="" />
		<!--- these are used to save a client's unsubmitted subject / message --->

		<cfset var local = {} />
		
		<!--- clear if already following --->
		<cfset $.run.it("discussionService.unfollowDiscussion",arguments) />
		<cfset $.run.it("discussionService.followDiscussion",arguments) />
		
		<cfset local.address = cgi.http_referer />
		
		<cfset local.address = $.link.setArg(local.address,"feedback") />
		<cfif arguments.discussionID neq "">
			<cfset local.address = $.link.setArg(local.address,"discussionID",arguments.discussionID) />
		</cfif>
		<cfif arguments.subject neq "">
			<cfset local.address = $.link.setArg(local.address,"subject",arguments.subject) />
		</cfif>
		<cfif arguments.message neq "">
			<cfset local.address = $.link.setArg(local.address,"message",arguments.message) />
		</cfif>
		<cfset local.address = $.link.setArg(local.address,"feedback") />
		
		<cflocation url="#local.address#" addToken="no" />
		
		<cfreturn true />
			
	</cffunction>
	
	<!--- --->
	
	<cffunction name="deleteDiscussion" access="public" output="true" returntype="void">
		<cfargument name="discussionID" required="true" />

		<cfset var local = {} />
			
		<cfset $.run.it('discussionService.deleteDiscussion',arguments) />
		
		<cflocation url="#$.site.getVar('rootURL')#/craftivity/forum_admin.cfm" addToken="no" />
		
		<cfreturn true />
			
	</cffunction>
	
	<!--- --->
	
	<cffunction name="archiveDiscussion" access="public" output="true" returntype="void">
		<cfargument name="discussionID" required="true" />

		<cfset var local = {} />
			
		<cfset $.database.save(
			table="discussion",
			id=arguments.discussionID,
			archive=1		
		) />
		
		<cflocation url="#cgi.http_referer#" addToken="no" />
		
		<cfreturn true />
			
	</cffunction>
	
	<!--- --->

</cfcomponent>